package com.yy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.mapper.DishMapper;
import com.yy.pojo.Dish;
import com.yy.pojo.User;
import com.yy.service.DishService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yyu
 * @description 针对表【t_dish(菜品是否在首页展示(0否1是)，一个食堂只能有一个)】的数据库操作Service实现
 * @createDate 2023-12-21 19:02:31
 */
@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish>
        implements DishService {

    @Autowired
    private DishMapper dishMapper;


    @Override
    public IPage<Dish> getDishesList(int pageNum, int pageSize, Dish dish) {
        IPage<Dish> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Dish> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (ObjectUtils.isNotEmpty(dish.getRestId())) {
            lambdaQueryWrapper.like(Dish::getRestId, dish.getRestId());
        }

        if (StringUtils.isNotEmpty(dish.getDishName())) {
            lambdaQueryWrapper.like(Dish::getDishName, dish.getDishName());
        }

        if (StringUtils.isNotEmpty(dish.getCuisine())) {
            lambdaQueryWrapper.eq(Dish::getCuisine, dish.getCuisine());
        }

        dishMapper.selectPage(page, lambdaQueryWrapper);
        return page;
    }

}




